package cn.cdiothree.controller;

import cn.cdiothree.dataobject.ActivityApply;
import cn.cdiothree.enums.ResultEnum;
import cn.cdiothree.exception.SellException;
import cn.cdiothree.service.ActivityApplyService;
import cn.cdiothree.vo.ActivityApplyVo;
import cn.cdiothree.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动报名
 * @author cumthing
 */
@RestController
@RequestMapping("/activity-apply")
public class ActivityApplyController {
    @Autowired
    private ActivityApplyService activityApplyService;

    /**
     * 活动报名
     * @param activityApply
     * @return
     */
    @PostMapping("/apply")
    public ResponseEntity<?> create(ActivityApply activityApply){
        if (activityApply==null){
            throw new SellException(ResultEnum.APPLY_NOT_NULL);
        }
        activityApplyService.create(activityApply);
        return ResponseEntity.status(HttpStatus.OK).body("恭喜您报名成功");
    }

    /**
     * 查看用户已经报名的活动
     * @param userId
     * @return
     */
    @GetMapping("/list")
    public ResultVo<List<ActivityApplyVo>> list(@RequestParam(value = "userId") Integer userId){
        List<ActivityApplyVo> activityApplyVoList = activityApplyService.findList(userId);
        return ResultVo.success(activityApplyVoList);
    }
}
